Creation time of a file
The following example gets the creation time of the specified file
C# .NET |
public static String DoTest() { string strRet = ""; try { string path = @"c:\MyFile.txt"; // Get the creation time of the file if (!File.Exists(path)) { // Create the file it does not exist. StreamWriter sw = File.CreateText(path); sw.Close(); } DateTime dt = File.GetCreationTime(path); // Give feedback to the user. if (DateTime.Now.Subtract(dt).TotalDays > 364) { strRet += String.Format("The file " + path + " is over a year old."); } else if (DateTime.Now.Subtract(dt).TotalDays > 30) { strRet += String.Format("The file " + path + " is over a month old."); } else if (DateTime.Now.Subtract(dt).TotalDays <= 1) { strRet += String.Format("The file " + path + " is less than a day old."); } else { strRet += String.Format("The file " + path + " was created on {0}", dt); } } catch (Exception e) { strRet += String.Format("The process failed: {0}", e.ToString()); } return strRet; } |
Blaze++ .NET |
static String DoTest() { String strRet = ""; try { String path = "c:\\MyFile.txt"; // Get the creation time of the file if (!File::Exists(path)) { // Create the file it does not exist. StreamWriter sw = File::CreateText(path); sw.Close(); } DateTime dt = File::GetCreationTime(path); // Give feedback to the user. if (DateTime::Now.Subtract(dt).TotalDays > 364) { strRet += String::Format("The file " + path + " is over a year old."); } else if (DateTime::Now.Subtract(dt).TotalDays > 30) { strRet += String::Format("The file " + path + " is over a month old."); } else if (DateTime::Now.Subtract(dt).TotalDays <= 1) { strRet += String::Format("The file " + path + " is less than a day old."); } else { strRet += String::Format("The file " + path + " was created on {0}", dt); } } catch (Exception e) { strRet += String::Format("The process failed: {0}", e.ToString()); } return strRet; } |